<template>
    <div class="container">
      <div class="box"><img src="http://210.12.11.251:34010/hygeian-peis/static/png/bg-d7895a87.png"/></div>
      <div class="box right-box">
        <h1>WelCome</h1>
        <h2>黄冈市人民医院</h2>
        <form class="login-form" @submit.prevent="login">
        <div class="input-group">
          <input type="text" v-model="username" placeholder="请输入账号" />
        </div>
        <div class="input-group">
          <input type="password" v-model="password" placeholder="请输入密码" />
        </div>
        <button type="submit" class="login-button">登录</button>
      </form>
      </div>
    </div>
  </template>
  
  <script>
import axios from 'axios';
import querystring from 'querystring'


  export default {
    name: 'Boxes',
    data() {
    return {
      username: '',
      password: '',
      scope: ''
    };
  },
  methods: {
    async login() {
      
      try {
        instance
        const response = await axios.post('http://210.12.11.251:34010/peis/ins/authserver/api/account/password-login?__tenant=3a11fd58-c553-629e-f953-fc4d93144698', {
          username: this.username,
          password: this.password,
          scope: "AccountService InstitutionService offline_access"
        },
        {
          headers: {
            'Content-Type':  'application/json' ,
          }
        }
      );
        // alert('登录成功');
        const token = response.data.token;
        
        if (token) {           
            localStorage.setItem('accessToken', token.accessToken);           
            localStorage.setItem('refreshToken', token.refreshToken);           
        }
        console.log('登陆成功',token);
      } catch (error) {
        alert('登录失败');
        console.error('登录失败:', error);
        
      }
    }
  }

  }
  </script>
  
  <style >
  body {
    background: linear-gradient(-45deg, #a4b4db, #f9fbff);
    height: 100vh; 
    margin: 0; 
}
  .container {
    display: flex;            
    justify-content: center;   
    align-items: center;      
    height: 100vh;           
  }
  
  
  .box {
    width: 400px;            
    height: 500px;          
    margin: 0;              
    background-color: #ffffff; 
    display: flex;            
    flex-direction: column;   
    justify-content: center;  
    align-items: center;      
    color: white;             
    font-size: 20px;          
    
    
  }
  
  .right-box {
    width:290px;
    height:420px;
  border-top-right-radius: 15px;   
  border-bottom-right-radius: 15px; 
  
  padding: 40px;
  flex-direction: column; 
    align-items: flex-start; 
}

  .box img{
    width: 400px;            
    height: 500px;
  }

  h1 {
    font-family: 'Microsoft Yahei', '微软雅黑', sans-serif;
    color: #333;
    font-size: 36px;
    font-weight: 700;
    
    margin: -100px 0 5px;
}

h2 {
  font-family: 'Microsoft Yahei', '微软雅黑', sans-serif;
   color: #333;
   font-size: 25px;
   font-weight: 600;
    margin: 0 0 50px;
    text-transform: uppercase;
}

.login-form {
  width: 100%;
}

.input-group {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 10px;
}

.input-group i {
  margin-right: 10px;
}

.input-group input {
  width: 100%;
  border: none;
  outline: none;
}

.login-button {
  width: 100%;
  padding: 10px;
  background-color: #3578e5;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
}

.login-button:hover {
  background-color: #2863c8;
}


  </style>